package cn.wgx.modules.sys.services;

import cn.wgx.commons.util.Validation;
import cn.wgx.modules.base.services.BaseService;
import cn.wgx.modules.sys.entity.mapper .SysUserJourneyMapper;
import cn.wgx.modules.sys.entity .SysUserJourney;
import cn.wgx.modules.sys.entity .SysUserJourneyExample;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service
public class SysUserJourneyService extends BaseService<SysUserJourney> {

    @Resource
    SysUserJourneyMapper mapper;

    @Transactional(readOnly = true)
    public List<SysUserJourney> getList(SysUserJourney record, Boolean desc) {
		SysUserJourneyExample example = new SysUserJourneyExample();
		if(record != null){
            SysUserJourneyExample.Criteria criteria = example.createCriteria();
            if(Validation.isNotNullOrZero(record.getCreateUserId())){
                criteria.andCreateUserIdEqualTo(record.getCreateUserId());
            }
        }
		example.setOrderByClause("createDate " + (desc?"desc": "asc"));
		return mapper.selectByExample(example);
    }


    @Override
    @Transactional(readOnly = true)
    public List<SysUserJourney> getListByIds(List<Integer> ids) {
        if(ids == null || ids.isEmpty()){
            return emptyList;
        }
        SysUserJourneyExample example = new SysUserJourneyExample();
        example.createCriteria().andJourney_idIn(ids);
        return mapper.selectByExample(example);
    }


    @Transactional(readOnly = true)
    public SysUserJourney getOne(Integer id) {
		return mapper.selectByPrimaryKey(id);
    }


    @Transactional
    public SysUserJourney insertOne( SysUserJourney record) {
        filter(record, true);
        mapper.insertSelective(record);
        return record;
    }


    @Transactional
    public SysUserJourney updateOne( SysUserJourney record) {
        filter(record, false);
        mapper.updateByPrimaryKeySelective(record);
        return record;

    }


    @Transactional
    public int deleteOne( Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }


    public void filter(SysUserJourney record, boolean isInsert){
        if(isInsert){

        }else{

        }
        super.filter(record, isInsert);
    }
}